﻿using Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace DAL
{
    /// <summary>
    /// 人员表
    /// </summary>
    public class UsersDal : BaseDal<SysUser>
    {
        public override string tablename
        {
            get { return "SysUser"; }
        }

        public override Dictionary<string, bool> PKName
        {
            get
            {
                Dictionary<string, bool> dic = new Dictionary<string, bool>();
                dic.Add("users_Id", true);
                return dic;
            }
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="UsersName"></param>
        /// <param name="UsersPwd"></param>
        /// <returns></returns>
        public List<SysUser> UsersLogin(string UsersName, string UsersPwd)
        {
            int j = 0;
            SqlParameter[]
                Parameter = new SqlParameter[]{
                    new SqlParameter("@users_Account",UsersName),
                    new SqlParameter("@users_Pwd",UsersPwd),
                    new SqlParameter("@users_IsState",j)
                };
            string Sql = Common.Common.GetTable<SysUser>(tablename, Parameter);
            DataTable dt = Common.DBHelp.GetDataSet(Sql);


            List<SysUser> user = new List<SysUser>();
            foreach (DataRow item in dt.Rows)
            {
                SysUser user1 = new SysUser();
                foreach (var i in user1.GetType().GetProperties())
                {
                    i.SetValue(user1, item[i.Name]);
                }
                user.Add(user1);
            }
            return user;

        }

        
       /// <summary>
       ///  根据部门编号查询改部门编号下的勘察员
       /// </summary>
       /// <param name="value"></param>
       /// <returns></returns>
        public List<SysUser> GetUsers(int newValue, int role)
        {
            SqlParameter[]
                Parameter = new SqlParameter[]{
                    new SqlParameter("@Department_Id",newValue),
                    new SqlParameter("@Roles_id",role)
                };
            string Sql = Common.Common.GetTable<SysUser>(tablename, Parameter);
            DataTable dt = Common.DBHelp.GetDataSet(Sql);


            List<SysUser> user = new List<SysUser>();
            foreach (DataRow item in dt.Rows)
            {
                SysUser user1 = new SysUser();
                foreach (var i in user1.GetType().GetProperties())
                {
                    i.SetValue(user1, item[i.Name]);
                }
                user.Add(user1);
            }
            return user;

        }
    }
}
